<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 用户行为
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-8-13
 +------------------------------------------------------------------------------
 */
namespace Admin\Controller;

class ActionController extends AdminController {

	/**
	 * 用户行为列表
	 */
	public function index(){
		//获取列表数据
// 		$action_list =   M('Action')->where(array('status'=>array('gt',-1)));
		$list   =   $this->lists(M('Action'));
		int_to_string($list);
		$this->assign('_list', $list);
		$this->meta_title = '用户行为';
		$this->display();
	}
	
	/**
     * 新增行为
     */
    public function add(){
    	if(IS_POST){
    		$this->update();
    	}else{
	        $this->meta_title = '新增行为';
	        $this->assign('list',null);
	        $this->display('edit');
    	}
    }

    /**
     * 编辑行为
     */
    public function edit(){
        $id = I('get.id');
        empty($id) && $this->error('参数不能为空！');
        if(IS_POST){
        	$this->update();
        }else{
	        $list = M('Action')->find($id);
	        $this->assign('list',$list);
	        $this->meta_title = '编辑行为';
	        $this->display('edit');
        }
    }

    /**
     * 更新行为
     */
    private function update(){
        $res = D('Action')->update();
        if(!$res){
            $this->error(D('Action')->getError());
        }else{
            $this->success('操作成功！',U('index'));
        }
    }
    
    /**
     * 行为日志列表
     */
    public function actionLog(){
        //获取列表数据
        $list   =   $this->lists(M('ActionLog'),array('create_time'=>array('gt',1459440000)));
        int_to_string($list);
        $this->assign('_list', $list);
        $this->meta_title = '行为日志';
        $this->display('action_log');
    }


    /**
     * 删除日志
     * @param mixed $ids
     */
    public function remove($ids = 0){
        empty($ids) && $this->error('参数错误！');
        if(is_array($ids)){
            $map['id'] = array('in', $ids);
        }elseif (is_numeric($ids)){
            $map['id'] = $ids;
        }
        $res = M('ActionLog')->where($map)->delete();
        if($res !== false){
            $this->success('删除成功！');
        }else {
            $this->error('删除失败！');
        }
    }

    /**
     * 清空日志
     */
    public function clear(){
        $res = M('ActionLog')->where('1=1')->delete();
        if($res !== false){
            $this->success('日志清空成功！');
        }else {
            $this->error('日志清空失败！');
        }
    }

}
